﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/zTree/v3/css/metroStyle/metroStyle.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/zTree/v3/js/ztree.min.js"))

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/jquery.layout/1.4.4/jquery.layout-latest.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/jquery.layout/1.4.4/jquery.layout-latest.min.js"))
<style type="text/css">
    .table {
        table-layout: fixed;
    }
</style>
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        ID：<input id="id" col="Id" type="text" />
                    </li>
                    <li>
                        名称：<input id="name" col="Name" type="text" />
                    </li>
                    <li>
                        手机：<input id="tel" col="Tel" type="text" />
                    </li>
                    <li>
                        城市：<input id="city" col="City" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>

        <div id="toolbar" class="btn-group-sm">
            <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
         initGrid();
     });

     function initGrid() {
         var queryUrl = '@Url.Content("~/RedBookFormManage/RedBookFormList/GetPageListJson")';
         $('#gridTable').ysTable({
             url: queryUrl,
             sortOrder: 'Asc',
             columns: [
                 { checkbox: true, visible: true },
                 { field: 'Id', title: 'ID', visible: true,width:'140px' },
                 { field: 'Name', title: '姓名' , align: 'center' ,width:'120px'},
                 { field: 'Tel', title: '电话', align: 'center',width:'120px' },
                 { field: 'City', title: '城市', align: 'center',width:'250px'},
                 { field: 'RealName', title: '所有者', align: 'center',width:'80px'},
                 {
                   field: 'SetTime', title: '创建时间',width:'120px', formatter: function (value, row, index) {
                         return ys.formatDate(value, "yyyy-MM-dd");
                     }
                 },
                 {
                        title: '操作',
                        align: 'center',
                        width:'150px',
                        formatter: function (value, row, index) {
                            if('@ViewBag.OperatorFlag'=='1')
                            {
                               var actions = [];
                            actions.push('<a class="btn btn-success btn-xs" href="#" onclick="optionMethod(\'' +row.Id+'\',1)"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="optionMethod(\'' +row.Id+'\',2)"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                            }
                         
                        }
                }
             ],
             queryParams: function (params) {
                 var pagination = $('#gridTable').ysTable('getPagination', params);
                 var queryString = $("#searchDiv").getWebControls(pagination);
                 return queryString;
             }
         });
     }

    function optionMethod(id, status) {
      if(status==1)
      {
            ys.openDialog({
             title: id > 0 ? "编辑推广" : "添加推广",
             content: '@Url.Content("~/RedBookFormManage/RedBookFormList/RedBookForm")' + '?id=' + id,
             callback: function (index, layero) {
                 var iframeWin = window[layero.find('iframe')[0]['name']];
                 iframeWin.saveForm(index);
             }
         });
      }
      else   //删除
      {   ys.confirm("确认要删除选中的这条数据吗？", function () {

                 ys.ajax({
                     url: '@Url.Content("~/RedBookFormManage/RedBookFormList/DeleteFormJson")' + '?ids=' + id,
                     type: "post",
                     success: function (obj) {
                         if (obj.Tag == 1) {
                             ys.msgSuccess(obj.Message);
                             searchGrid();
                         }
                         else {
                             ys.msgError(obj.Message);
                         }
                     }
                 });
             });

      }

    }

    function showImage(imageUrl) {
        var html = '<img src="' + imageUrl + '" width="100%" height="100%" class="img-responsive" />';
        ys.openDialogContent({
            content: html,
            width: 'auto',
            height: 'auto',
            closeBtn: true
        });
    }
     function searchGrid() {
         $('#gridTable').ysTable('search');
         resetToolbarStatus();
     }

     function showSaveForm(bAdd) {
         var id = 0;
         if (!bAdd) {
             var selectedRow = $("#gridTable").bootstrapTable("getSelections");
             if (!ys.checkRowEdit(selectedRow)) {
                 return;
             }
             else {
                 id = selectedRow[0].Id;
             }
         }
         ys.openDialog({
             title: id > 0 ? "编辑推广" : "添加推广",
             content: '@Url.Content("~/RedBookFormManage/RedBookFormList/RedBookForm")' + '?id=' + id,
             callback: function (index, layero) {
                 var iframeWin = window[layero.find('iframe')[0]['name']];
                 iframeWin.saveForm(index);
             }
         });
     }

     function deleteForm() {
         var selectedRow = $("#gridTable").bootstrapTable("getSelections");
         if (ys.checkRowDelete(selectedRow)) {
             ys.confirm("确认要删除选中的" + selectedRow.length + "条数据吗？", function () {
                 var ids = ys.getIds(selectedRow);
               
                 ys.ajax({
                     url: '@Url.Content("~/RedBookFormManage/RedBookFormList/DeleteFormJson")' + '?ids=' + ids,
                     type: "post",
                     success: function (obj) {
                         if (obj.Tag == 1) {
                             ys.msgSuccess(obj.Message);
                             searchGrid();
                         }
                         else {
                             ys.msgError(obj.Message);
                         }
                     }
                 });
             });
         }
     }
</script>

